package cn.han.io;

import java.io.*;

public class TestIn2 {
    public static void main(String[] args) {
//        method1();
        method2();
    }

    private static void method2() {
        Reader r = null;
        try {
            r = new BufferedReader(new FileReader("D:\\ready\\5.txt"));
//            r = new BufferedReader(new FileReader(new File("D:\\ready\\5.txt")));
//            r = new BufferedReader(new InputStreamReader(new FileInputStream(new File("D:\\ready\\5.txt"))))
            int b;
            while ((b = r.read()) != -1) {
                System.out.println(b);
            }
        } catch (Exception e) {

            e.printStackTrace();
        } finally {
            try {
                r.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method1() {
        //1.创建流对象
        Reader r = null;
        try {
//            r = new FileReader(new File("D:\\ready\\5.txt"));
            r = new FileReader("D:\\ready\\5.txt");
            //2.使用流对象
            int b;
            while ((b = r.read()) != -1) {
                System.out.println(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //3.关闭流对象
            try {
                r.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
